package com.sunsharing.transport.mina;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 *<pre><b><font color="blue">MyProtocolCodecFactory</font></b></pre>
 *
 *<pre><b>&nbsp;--描述说明--</b></pre>
 * <pre></pre>
 * <pre>
 * <b>--样例--</b>
 *   MyProtocolCodecFactory obj = new MyProtocolCodecFactory();
 *   obj.method();
 * </pre>
 * JDK版本：JDK1.5
 * @author  <b>何鑫</b>
 */
public class MyProtocolCodecFactory implements ProtocolCodecFactory {
	
	private final MyProtocolDecoder decoder ;
	private final MyProtocolEncoder encoder ;
	
	/**
	 * 无参构造函数
	 */
	public MyProtocolCodecFactory(){
		this(Charset.defaultCharset());
	}
	
	/**
	 * 带参数构造函数，设置编码器和解码器的字符集编码
	 * @param charset
	 */
	public MyProtocolCodecFactory(Charset charset){
		this.decoder = new MyProtocolDecoder(charset);
		this.encoder = new MyProtocolEncoder(charset);
	}
	  	  
	/* (non-Javadoc)
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder(org.apache.mina.core.session.IoSession)
	 */
	public ProtocolDecoder getDecoder(IoSession arg0) throws Exception {
		return this.decoder;
	}

	/* (non-Javadoc)
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder(org.apache.mina.core.session.IoSession)
	 */
	public ProtocolEncoder getEncoder(IoSession arg0) throws Exception {
		return this.encoder;
	}

}
